import os
import pickle
import time
import datetime

def judgeTime(time_limit):
    path = "data/data_clean_key_cut"
    doc_right = os.listdir(path)
    now = datetime.datetime.now()
    if time_limit=='一周内':
        time_comp=now + datetime.timedelta(weeks=-1)
    elif time_limit=='一个月内':
        time_comp = now + datetime.timedelta(days=-30)
    elif time_limit=='一年内':
        time_comp = now + datetime.timedelta(days=-365)
    else:
        #时间不限
        time_comp=now
        return doc_right
    #判断doc列表
    doc_in_time=[]
    path = "data/data_clean_key_cut/"
    for doc in doc_right:
        doc_path=path+str(doc)
        f1 = open(doc_path, 'rb')
        doc_detail = pickle.load(f1)
        doc_time=doc_detail['time']
        doc_time=datetime.datetime.strptime(doc_time,'%Y-%m-%d %H:%M:%S')

        if (doc_time<time_comp):
            doc_in_time.append(doc)

    print("testhaha")
    return doc_in_time
        